<?php

// +----------------------------------------------------------------------
// | EasyAdmin
// +----------------------------------------------------------------------
// | PHP交流群: 763822524
// +----------------------------------------------------------------------
// | 开源协议  https://mit-license.org 
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zhongshaofa/EasyAdmin
// +----------------------------------------------------------------------

namespace app\model;
use think\Exception;
use think\Model;
/**
 * 有关时间的模型
 * Class TimeModel
 * @package app\common\model
 */
class TimeModel extends Model
{
    /**
     * 自动时间戳类型
     * @var string
     */
    protected $autoWriteTimestamp = true;

    /**
     * 添加时间
     * @var string
     */
    protected $createTime = 'create_time';

    /**
     * 更新时间
     * @var string
     */
    protected $updateTime = 'update_time';

    public static function getOneName($id  ,$name)
    {
        return self::where('id' , $id)->value($name) ;
    }
    public static function getOne($id )
    {
        return self::where('id' , $id)->find() ;
    }

    public static function getOneCheck($id , $msg )
    {
        $info = self::where('id' , $id)->where('status' , 1)->find() ;
        if($info == null)
        {
            //($msg) ;
        }
        return $info ;
    }

    public static function getColumnName($id , $name , $arr = false)
    {
        $data = self::where('id' , 'in' , $id)->column($name) ;
        if($arr == true)
        {
            return $data ;
        }
        return implode(',' , $data) ;
    }
    public static function getWhereOne($where)
    {
        $info = self::where($where)->find() ;
        if($info == null)
        {
            throw new Exception('数据不存在') ;
        }
        return $info;
    }
    public static function dataDelete($id = 0)
    {
        self::update([
            'status' => -1 ,
            'delete_time' => time() ,
        ] , ['id' => $id]) ;
    }
    public static function arrayDelete($wh)
    {
        self::update([
            'status' => -1 ,
            'delete_time' => time() ,
        ] , $wh) ;
    }
    public static function dataIsset($id , $filed , $value)
    {
        $total = self::where($filed , $value)->where('id' , '<>' , $id)->where('status' , 1)->count() ;
        return $total ;
    }
    public static function listAll($field)
    {
        return self::where('status' , 1)->field($field)->order('sort desc')->select() ;
    }
}